/*
 * @Author: your name
 * @Date: 2024-03-21 18:59:36
 * @LastEditTime: 2024-04-05 11:16:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\1.两数之和.cpp
 */
/*
 * @lc app=leetcode.cn id=1 lang=cpp
 *
 * [1] 两数之和
 */

// @lc code=start
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> map;// 值->下标
        for(int i= 0; i < nums.size(); i++){
            if(map.find(target-nums[i]) != map.end()){
                // 找到了
                return {i,map[target-nums[i]]};
            }
            else{
                map[nums[i]] = i;
            }
        }
        return {};
        
    }
};
// @lc code=end
// 用哈希表记录一下遍历的数字
